package cn.itsource.pethome_0310.org.controller;

import cn.itsource.pethome_0310.basic.domain.BaseQuery;
import cn.itsource.pethome_0310.basic.domain.JSONResult;
import cn.itsource.pethome_0310.org.domain.Department;
import cn.itsource.pethome_0310.org.domain.Employee;
import cn.itsource.pethome_0310.org.service.EmployeeService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/empl")
public class EmployeeController {
    @Autowired
    EmployeeService employeeService;

    /**
    *1.请求方式:get
    *2.url: /empl/findAll
    *3.请求参数:空
    *4.响应参数:JSONResult
    **/
    @GetMapping("/findAll")
    public JSONResult findAll(){
      List<Employee> employees = employeeService.findAll();
      return JSONResult.success(employees);
    }
    /**
     * 高级分页查询
     */
    @PostMapping("/findPage")
    public JSONResult findPage(@RequestBody BaseQuery baseQuery){
        return JSONResult.success(employeeService.basePageList(baseQuery));
    }
    @GetMapping("/delete/{id}")
    @ApiOperation(value="删除用户", notes="删除用户")
    public JSONResult delete(@PathVariable Long id){
        employeeService.delete(id);
        return null;
    }
    /**
     *1.请求方式: post
     *2.url:dept/add
     *3.请求参数:Dept对象
     *4.响应参数:JSONResult
     **/
    @PostMapping("/add")
    @ApiOperation(value="新增员工", notes="新增员工")
    public JSONResult add(@RequestBody @Valid Employee employee){

         employeeService.insert(employee);
        return null;
    }
    @PostMapping("/batchDelete")
    @ApiOperation(value="批量删除", notes="批量删除")
    public JSONResult batchDelete(@RequestBody List<Long> ids){
        System.out.println(ids);
         employeeService.batchDelete(ids);
        return null;
    }

}
